﻿using Ledict.ConditionExtract.Base;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Ledict.ConditionExtract.Frm.NodeTree
{
    /// <summary>
    /// 根据法规查询条件
    /// </summary>
    public partial class NodeTreeCaseCondition : BaseForm
    {
        private readonly QuoteLawRelBLL quoteLawRelBLL = new QuoteLawRelBLL();

        ///// <summary>
        ///// 查询条件
        ///// </summary>
        //public string conditionData { get; set; }

        ///// <summary>
        ///// 法律库法条模糊查询条件
        ///// </summary>
        //public string provCondition52 { get; set; }

        /// <summary>
        /// 行政执法库法条模糊查询条件
        /// </summary>
        // public string provCondition12 { get; set; }

        /// <summary>
        /// 查询条件类
        /// </summary>
        public NodeTreeCaseConditionData conditionDataModel { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public NodeTreeCaseCondition()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 界面加载事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NodeTreeCaseCondition_Load(object sender, EventArgs e)
        {
            checkedListBoxEffectiveGrade.DataSource = quoteLawRelBLL.GetHeadWindows();
            checkedListBoxEffectiveGrade.DisplayMember = "E_Name";
            checkedListBoxEffectiveGrade.ValueMember = "E_ID";
        }

        /// <summary>
        /// 确定按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEnter_Click(object sender, EventArgs e)
        {
            conditionDataModel = new NodeTreeCaseConditionData();
            conditionDataModel.PromuDateStart = Convert.ToDateTime(PromuDateStart.Text);
            conditionDataModel.PromuDateEnd = Convert.ToDateTime(PromuDateEnd.Text);
            //选择的效力等级
            if (checkedListBoxEffectiveGrade.CheckedItems.Count > 0)
            {
                conditionDataModel.EIDs = new List<int>();
                foreach (var item in checkedListBoxEffectiveGrade.CheckedItems)
                {
                    SYS_EffectiveGrade se = item as SYS_EffectiveGrade;
                    conditionDataModel.EIDs.Add(se.E_ID);
                }
            }
            
            if (!string.IsNullOrEmpty(LawKeyWord.Text.Trim()))
            {
                conditionDataModel.LName = LawKeyWord.Text.Trim();
            }
            if (!string.IsNullOrEmpty(ProvKeyWord.Text.Trim()))
            {
                conditionDataModel.LpText = ProvKeyWord.Text.Trim();
            }

            #region 旧有代码
            //var ChooseWhere = new StringBuilder();
            //ChooseWhere.Append(" 1=1 ");
            //var ChooseHWType = new StringBuilder();
            //var isallHWType = 0;

            //#region 类别

            //var collection = checkedListBoxEffectiveGrade.CheckedItems;
            //if (collection.Count == 0)
            //{
            //    isallHWType = 1;
            //}
            //else
            //{
            //    for (var i = 0; i < collection.Count; i++)
            //    {
            //        SYS_EffectiveGrade seg = collection[i] as SYS_EffectiveGrade;

            //        //var dr = (DataRowView)collection[i];
            //        //if (string.IsNullOrEmpty(dr.Row["HWType"].ToString())) //包含全部
            //        //{
            //        //    isallHWType = 1;
            //        //    break;
            //        //}
            //        if (!string.IsNullOrEmpty(ChooseHWType.ToString()))
            //        {
            //            ChooseHWType.Append(",");
            //        }
            //        ChooseHWType.Append("'" + seg.E_ID + "'");
            //    }
            //}
            //if (collection.Count > 0 && isallHWType == 0)
            //    ChooseWhere.Append(" and T_Law.EffectiveGrade_ID in (" + ChooseHWType + ")");

            //#endregion

            //if (!string.IsNullOrEmpty(LawKeyWord.Text.Trim()))
            //    ChooseWhere.Append(" and T_Law.L_Name like '%" + LawKeyWord.Text.Trim() + "%'"); //法律名称

            //ChooseWhere.Append(" and   T_Law.L_DateIssued >='" + Convert.ToDateTime(PromuDateStart.Text).ToString("yyyy-MM-dd") +
            //                   "' and T_Law.L_DateIssued <='" + Convert.ToDateTime(PromuDateEnd.Text).ToString("yyyy-MM-dd") +
            //                   "'"); //公布时间
            //if (!string.IsNullOrEmpty(ProvKeyWord.Text.Trim()))
            //{
            //    provCondition52 = " and T_Law_Article.LP_Text like'%" + ProvKeyWord.Text.Trim() + "%'";
            //}
            ////if (!string.IsNullOrEmpty(ProvKeyWord.Text.Trim()))
            ////{
            ////    provCondition12 = " and discretion_benchmark.BenchmarkText like'%" + ProvKeyWord.Text.Trim() + "%'";
            ////}
            //conditionData = ChooseWhere.ToString(); 
            #endregion

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }
    }

   
}
